package com.ruoyi.cmenonmetal.service.impl;

import com.ruoyi.cmenonmetal.domain.ZsPrintProcess;
import com.ruoyi.cmenonmetal.mapper.ZsPrintProcessMapper;
import com.ruoyi.cmenonmetal.service.IZsPrintProcessService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 打印处理Service业务层处理
 *
 * @author zousong
 * @date 2022-02-22
 */
@Service
public class ZsPrintProcessServiceImpl implements IZsPrintProcessService
{
    @Autowired
    private ZsPrintProcessMapper zsPrintProcessMapper;

    /**
     * 查询打印处理
     *
     * @param id 打印处理主键
     * @return 打印处理
     */
    @Override
    public ZsPrintProcess selectZsPrintProcessById(Long id)
    {
        return zsPrintProcessMapper.selectZsPrintProcessById(id);
    }

    /**
     * 查询打印处理列表
     *
     * @param zsPrintProcess 打印处理
     * @return 打印处理
     */
    @Override
    public List<ZsPrintProcess> selectZsPrintProcessList(ZsPrintProcess zsPrintProcess)
    {
        return zsPrintProcessMapper.selectZsPrintProcessList(zsPrintProcess);
    }

    /**
     * 新增打印处理
     *
     * @param zsPrintProcess 打印处理
     * @return 结果
     */
    @Override
    public int insertZsPrintProcess(ZsPrintProcess zsPrintProcess)
    {
        return zsPrintProcessMapper.insertZsPrintProcess(zsPrintProcess);
    }

    /**
     * 修改打印处理
     *
     * @param zsPrintProcess 打印处理
     * @return 结果
     */
    @Override
    public int updateZsPrintProcess(ZsPrintProcess zsPrintProcess)
    {
        //修改打印处理时长
        if(zsPrintProcess.getStartTime() == null || zsPrintProcess.getEndTime() == null){
            System.out.println("测试");
            return zsPrintProcessMapper.updateZsPrintProcess(zsPrintProcess);
        }
        long time = DateUtils.zxgetDatePoor(zsPrintProcess.getEndTime(),zsPrintProcess.getStartTime());
        zsPrintProcess.setPrintTime(time);

        return zsPrintProcessMapper.updateZsPrintProcess(zsPrintProcess);
    }

    /**
     * 批量删除打印处理
     *
     * @param ids 需要删除的打印处理主键
     * @return 结果
     */
    @Override
    public int deleteZsPrintProcessByIds(Long[] ids)
    {
        return zsPrintProcessMapper.deleteZsPrintProcessByIds(ids);
    }

    /**
     * 删除打印处理信息
     *
     * @param id 打印处理主键
     * @return 结果
     */
    @Override
    public int deleteZsPrintProcessById(Long id)
    {
        return zsPrintProcessMapper.deleteZsPrintProcessById(id);
    }
}
